import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   如果设置为 true，项目将不会显示在侧边栏中（默认为 false）
 * alwaysShow: true               如果设置为 true，将始终显示根菜单
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },

  { path: '/404', component: () => import('@/views/404'), hidden: true },

  // 访问 / 注册 Layout 组件
  { path: '/', component: Layout }

  /*  // 使用动态路由
 {
   path: '/',
   component: Layout,
   redirect: '/index',
   name: '首页管理',
   meta: { title: '首页管理', icon: 'dashboard' },
   children: [
     {
       path: 'index',
       name: '轮播图管理',
       component: () => import('@/views/dashboard/banner'),
       meta: { title: '轮播图管理', icon: 'dashboard' }
     }
   ]
 },

 // 自定义讲师管理
 {
   path: '/edu',
   component: Layout,
   redirect: '/edu/table',
   name: '讲师管理',
   // 利用 meta 配置项 设置标题 和 图标 可以通过当前路由的 $route 来获取到，不是全局路由 $router！！！
   meta: { title: '讲师管理', icon: 'el-icon-user' },
   children: [
     {
       path: 'table',
       name: '讲师列表',
       component: () => import('@/views/edu/teacher/list'),
       meta: { title: '讲师列表', icon: 'el-icon-menu' }
     },
     {
       path: 'tree',
       name: '添加讲师',
       component: () => import('@/views/edu/teacher/save'),
       meta: { title: '添加讲师', icon: 'el-icon-circle-plus-outline' }
     },
     {
       path: 'table/:id',  // 通过路由，进行传递 id 参数，为了跳转只后，列表按钮保持高亮，我们可以设置同名路由 table
       name: '编辑讲师',
       component: () => import('@/views/edu/teacher/save'),
       meta: { title: '编辑讲师', activeMenu: '/edu/table' },
       hidden: true // 不显示到左侧菜单栏
     }
   ]
 },

 //   创建课程分类管理模块
 {
   path: '/subject',
   component: Layout,
   redirect: '/subject/list',
   name: '课程分类管理',
   meta: { title: '课程分类管理', icon: 'tree' },
   children: [
     {
       path: 'list',
       name: '课程分类列表',
       component: () => import('@/views/edu/subject/list'),
       meta: { title: '课程分类列表', icon: 'el-icon-menu' }
     },
     {
       path: 'save',
       name: '导入课程分类',
       component: () => import('@/views/edu/subject/save'),
       meta: { title: '添加课程分类', icon: 'el-icon-circle-plus-outline' }
     }
   ]
 },
 //   创建课程分类管理模块
 {
   path: '/sta',
   component: Layout,
   redirect: '/sta/create',
   name: '统计分析',
   meta: { title: '统计分析', icon: 'el-icon-s-data' },
   children: [
     {
       path: 'create',
       name: '生成数据',
       component: () => import('@/views/sta/create'),
       meta: { title: '生成数据', icon: 'el-icon-circle-plus' }
     },
     {
       path: 'show',
       name: '统计图表',
       component: () => import('@/views/sta/show'),
       meta: { title: '图表显示', icon: 'el-icon-data-line' }
     }
   ]
 },

 //   权限管理
 {
   path: '/acl',
   component: Layout,
   redirect: '/acl/user/list',
   name: '权限管理',
   meta: { title: '权限管理', icon: 'el-icon-setting' },
   children: [
     {
       path: 'user/list',
       name: '用户管理',
       component: () => import('@/views/acl/user/list'),
       meta: { title: '用户管理', icon: 'el-icon-user-solid' }
     },
     {
       path: 'role/list',
       name: '角色管理',
       component: () => import('@/views/acl/role/list'),
       meta: { title: '角色管理', icon: 'el-icon-share' }
     },
     {
       path: 'role/form',
       name: '角色添加',
       component: () => import('@/views/acl/role/form'),
       meta: { title: '角色添加', activeMenu: '/acl/role/list' },
       hidden: true
     },
     {
       path: 'role/update/:id',
       name: '角色修改',
       component: () => import('@/views/acl/role/form'),
       meta: { title: '角色修改', activeMenu: '/acl/role/list' },
       hidden: true
     },
     {
       path: 'role/distribution/:id',
       name: '角色权限',
       component: () => import('@/views/acl/role/roleForm'),
       meta: { title: '角色权限', activeMenu: '/acl/role/list' },
       hidden: true
     },
     {
       path: 'menu/list',
       name: '菜单管理',
       component: () => import('@/views/acl/menu/list'),
       meta: { title: '菜单管理', icon: 'el-icon-s-operation' }
     },
     {
       path: 'user/add',
       name: '用户添加',
       component: () => import('@/views/acl/user/form'),
       meta: { title: '用户添加', activeMenu: '/acl/user/list' },
       hidden: true
     },
     {
       path: 'user/update/:id',
       name: '用户修改',
       component: () => import('@/views/acl/user/form'),
       meta: { title: '用户修改', activeMenu: '/acl/user/list' },
       hidden: true
     },
     {
       path: 'user/role/:id',
       name: '分配角色',
       component: () => import('@/views/acl/user/roleForm'),
       meta: { title: '用户角色', activeMenu: '/acl/user/list' },
       hidden: true
     }

   ]
 },

// 创建课程信息管理模块
 {
   path: '/course',
   component: Layout,
   redirect: '/course/list',
   name: '课程管理',
   meta: { title: '课程管理', icon: 'el-icon-s-management' },
   children: [
     { // 课程列表
       path: 'list',
       name: '课程管理列表',
       component: () => import('@/views/edu/course/list'),
       meta: { title: '课程管理列表', icon: 'el-icon-menu', noCache: true },
     },
     // 课程列表 修改功能路由 --------------------
     {
       path: 'list/info/:id',
       name: 'EduCourseInfoEdit',
       component: () => import('@/views/edu/course/utils/info'),
       meta: { title: '编辑课程基本信息', icon: 'tree', activeMenu: '/course/list' },
       hidden: true
     },
     {
       path: 'list/chapter/:id',
       name: 'EduCourseChapterEdit',
       component: () => import('@/views/edu/course/utils/chapter'),
       meta: { title: '编辑课程大纲', icon: 'tree', activeMenu: '/course/list' },
       hidden: true
     },
     //  --------------------课程列表 修改路由

     // 正常添加课程信息 , 由于权限使用的是另外一种路由模块，没有三级菜单栏，为了统一，方便后端拼接 json ，这里进行修改
     // {
     //   path: 'save',
     //   name: '添加课程',
     //   component: () => import('@/views/edu/course/save'),
     //   redirect: '/course/save/info',
     //   meta: { title: '添加课程', icon: 'el-icon-circle-plus-outline', noCache: true },
     //   // 三级子路由，方便跳转
     //   children: []    // 将三级路由移出来，因为后端不好拼接路由
     // },

     // 修改后的 添加课程信息
     {
       path: 'info',
       name: 'info',
       component: () => import('@/views/edu/course/utils/info'),
       meta: { title: '发布课程',icon: 'el-icon-circle-plus-outline'},
     },
     // 另外一种路由规则，对应的填写部分路由 ------------------------------------
     {  // 这里是编辑课程信息的 ！！   noCache 表示缓存是否禁用   hidden: true 不在菜单栏显示
       path: 'save/info/:id', // save 路由不要改，否则代码里面也要改
       name: 'EduCourseInfoEdit',
       component: () => import('@/views/edu/course/utils/info'),
       meta: { title: '编辑课程基本信息', noCache: true, activeMenu: '/course/info' },
       hidden: true
     },
     {
       path: 'save/chapter/:id',
       name: 'EduCourseChapterEdit',
       component: () => import('@/views/edu/course/utils/chapter'),
       meta: { title: '编辑课程大纲',  noCache: true, activeMenu: '/course/info' },
       hidden: true
     },
     {
       path: 'save/publish/:id',
       name: 'EduCoursePublishEdit',
       component: () => import('@/views/edu/course/utils/publish'),
       meta: { title: '课程发布', noCache: true, activeMenu: '/course/info' },
       hidden: true
     }
     //  ------------------------------------ 添加课程信息填写部分路由
   ]
 },*/

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
